﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public partial class ItemForm : Form
    {
        Item set;
        event NewItemEventHandler newItemEvent;

        public ItemForm(SelfCheckStation parent, Item contained)
        {
            try
            {
                set = contained;

                InitializeComponent();
                newItemEvent += parent.itemhandler;

                textBox1.Text = set.upcnum.ToString();
                textBox2.Text = set.name;
                textBox3.Text = string.Format("{0:C}", set.price);
                textBox4.Text = string.Format("{0:P}", (((Double)set.discount)/100));
                richTextBox1.Text = set.description;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Item i = new Item();
                //parse input
                if ( newItemEvent != null)
                    newItemEvent(this, i);
                Dispose();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
    }
}
